USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Products-Insert]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	Insert record into table [dbo].[Dealers_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Products-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Products-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Products-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Dealers_Products](/*[ID], [Dealer_ID], [Product_ID], [MeasureUnit_ID]*/)
	VALUES     (/*@ID, @Dealer_ID, @Product_ID, @MeasureUnit_ID*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Products]
    WHERE  ( [ID] =@ID )
	AND  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Product_ID] =@Product_ID )
	AND  ( [MeasureUnit_ID] =@MeasureUnit_ID )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Products-update]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	Update record in table [dbo].[Dealers_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Products-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Products-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Products-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Dealers_Products] SET 
		/*[ID] =@ID, 
		[Dealer_ID] =@Dealer_ID, 
		[Product_ID] =@Product_ID, 
		[MeasureUnit_ID] =@MeasureUnit_ID*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Products]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Products-Insert-Update]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	Insert OR Update record into table [dbo].[Dealers_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Products-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Products-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Products-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Dealers_Products] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Dealers_Products](/*[ID], [Dealer_ID], [Product_ID], [MeasureUnit_ID]*/)
		VALUES     (/*@ID, @Dealer_ID, @Product_ID, @MeasureUnit_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Dealers_Products] SET 
			/*[ID] =@ID, 
			[Dealer_ID] =@Dealer_ID, 
			[Product_ID] =@Product_ID, 
			[MeasureUnit_ID] =@MeasureUnit_ID*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Products]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Products-Delete]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	delete records from table [dbo].[Dealers_Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Products-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Products-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Products-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@MeasureUnit_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Dealers_Products]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Products-Select]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	select records from table [dbo].[Dealers_Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Products-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Products-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Products-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@MeasureUnit_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Dealers_Products]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )*/
END
GO
-- =============================================
